package com.zw.yzk.kabu.mapper;

import com.zw.yzk.kabu.data.network.entity.StoreEntity;
import com.zw.yzk.kabu.model.GoodsModel;
import com.zw.yzk.kabu.model.StoreModel;
import com.zw.yzk.kabu.utils.CalculateUtils;

import java.util.ArrayList;
import java.util.List;

import javax.inject.Inject;

/**
 * Created by zhanwei on 2017/3/14.
 */

public class StoreMapper {

    @Inject
    public StoreMapper() {
    }

    public StoreModel transfer(StoreEntity entity) {
        StoreModel model = new StoreModel();
        model.setGoodsModel(transfer(entity.result.goodsList));
        if (entity.result.details == null) {
            return model;
        }
        StoreModel.ShopInfo shopInfo = new StoreModel.ShopInfo();
        shopInfo.setImage(entity.result.details.shopHead);
        shopInfo.setShopSign(entity.result.details.shopSign);
        shopInfo.setCollected(entity.result.details.isCollected == 1);
        shopInfo.setOwnerPhone(entity.result.details.ownerPhone);
        shopInfo.setShopName(entity.result.details.shopName);
        shopInfo.setShopId(entity.result.details.shopId);
        shopInfo.setShopOwnerId(entity.result.details.shopOwnerId);
        shopInfo.setShopImage(entity.result.details.shopImage);
        shopInfo.setShopOwnerName(entity.result.details.shopOwnerName);

        model.setShopInfo(shopInfo);
        return model;
    }

    public GoodsModel transfer(StoreEntity.Goods goods) {
        GoodsModel model = new GoodsModel();
        model.setImage(goods.image);
        model.setName(goods.name);
        model.setPrice(CalculateUtils.getRealPrice(goods.originalPrice, goods.discountedPrice));
        model.setShopName(goods.shopName);
        model.setShopId(goods.shopId);
        model.setId(goods.id);
        model.setBuyable(goods.isBuyable == 1);

        return model;
    }

    public List<GoodsModel> transfer(List<StoreEntity.Goods> goodsList) {
        List<GoodsModel> modelList = new ArrayList<>();
        if (goodsList == null || goodsList.isEmpty()) {
            return modelList;
        }
        for (StoreEntity.Goods goods : goodsList) {
            modelList.add(transfer(goods));
        }
        return modelList;
    }
}
